package day1;

import java.io.Serializable;
import java.util.Objects;

/**
 * @author oldliu
 * @since 1.0
 */
public class Pet implements Comparable<Pet>, Serializable {
    protected String name;
    //禁止序列化
    transient int love;
    private int health;

    public Pet() {
    }

    public Pet(int love, int health) {
        this.love = love;
        this.health = health;
    }

    public Pet(String name, int love, int health) {
        this.name = name;
        this.love = love;
        this.health = health;
    }

    public void show() {
        System.out.println("名字叫" + name + "，健康值是：" + health + ",可爱程度：" + love);
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getLove() {
        return love;
    }

    public void setLove(int love) {
        this.love = love;
    }

    public int getHealth() {
        return health;
    }

    public void setHealth(int health) {
        this.health = health;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Pet pet = (Pet) o;
        return Objects.equals(name, pet.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name);
    }
//    //散列码
//    @Override
//    public int hashCode() {
//        return this.name==null?0:this.name.hashCode();
//    }
//
//    @Override
//    public boolean equals(Object obj) {
//        //动物名字一样，就是一样
//        if(! (obj instanceof Pet))
//            return false;
//
//        Pet d=(Pet)obj;
//        if(this.name==null &&d.name==null)
//            return true;
//        if(this.name!=null &&this.name.equals(d.name))
//            return true;
//
//        return  false;
//    }

    @Override
    public String toString() {

        return "名字叫"+this.name+"，健康值是"+this.health+",可爱程度"+this.love;
    }

    @Override
    public int compareTo(Pet o) {
       // return this.name.compareTo(o.name);
        return this.health+this.love-o.health-o.love;
    }
}
